<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\helpers\Url;
use yii\bootstrap\ActiveForm;

/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app', 'Links');
$this->params['breadcrumbs'][] = $this->title;
?>
<hr/>
<div class="links-index">

    <p>
        <?= Html::a(Yii::t('app', '新增链接'), ['create'], ['class' => 'btn btn-success']) ?>
		<?= Html::a(Yii::t('app', '删除链接'), 'javascript:submits()', ['class' => 'btn btn-danger', 'data-confirm' => '确定要删除吗？']) ?>
    </p>

	<?php ActiveForm::begin([
		'action' => Url::to(['links/delall']),
		'options' => [
			'class' => 'submits'
		]
	]) ?>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
			['class' => \yii\grid\CheckboxColumn::className()],

            'id',
			[
				'header' => '<a href="javascript:void()">链接名称</a>',
				'content' => function ($model) {
					return $model->name;
				}
			],

			[
				'header'=>'<a href="javascript:void()">链接地址</a>',
				// 'class' => yii\grid\Column::className(),
				'content'=>function ($model, $key, $index, $column){
					if (preg_match('/http/', $model->url, $isHttp)) {
						return Html::a($model->url, $model->url);
					} else {
						return Html::a($model->url, 'javascript:void()');
					}
				}
			],

			[
				'header' => '<a href="javascript:void()">logo</a>',
				'content' => function ($model) {
					return $model->image;
				}
			],

            'sort',
            // 'create_time',

            [
				'class' => 'yii\grid\ActionColumn',
				'header' => '<a href="javascript:void()">操作</a>',
				'template' => '{update} {delete}',
			],
        ],
    ]); ?>
	<?php ActiveForm::end() ?>
</div>
<script>
	<?php $this->beginBlock('js_end') ?>

	$(function(){
		highlight_subnav("<?= Url::to(['links/index']) ?>");
	});

	<?php $this->endBlock() ?>
</script>
<?php $this->registerJs($this->blocks['js_end'], \yii\web\View::POS_END); ?>
